package aiguigu04.example.exer5;

/**
 * ClassName: StudentUtil
 * Package: aiguigu04.example.exer5
 * Description:
 *
 * @Author ZY
 * @Create 2024/9/28 14:12
 * @Version 1.0
 */
public class StudentUtil {

    public void printStudentsWithState(Student[] students,int state){
        for (int i = 0; i < students.length; i++) {
            if (3 == students[i].state){
                Student stu = students[i];
                System.out.println(stu.show());
            }
        }
    }
    //遍历指定的学生数组
    public void printStudents(Student[] students){
        for (int i = 0; i < students.length; i++) {
            System.out.println(students[i].show());
        }
    }

    //排序
    public void sortStudents(Student[] students){
        //外层决定循环的次数
        for (int i = 0; i < students.length - 1; i++) {
            for (int j = 0; j < students.length - 1 - i; j++) {
                //如果上一个学生的成绩比下一个学生的成绩高，就交换他们的位置
                if (students[j].score > students[j + 1].score){
                    Student temp = students[j];
                    students[j] = students[j + 1];
                    students[j + 1] = temp;
                }
            }
        }
    }
}
